﻿using Abp.Application.Services;
using Abp.Application.Services.Dto;
using Abp.Authorization;
using Abp.Domain.Repositories;
using Abp.Linq.Extensions;
using MVlog.Authorization;
using MVlog.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MVlog.Application
{
    [AbpAuthorize(AppPermissions.Pages_Video)]
    public class VideoAppService : AsyncCrudAppService<Video, VideoDto, long, GetVideoInput, CreateVideoInput, UpdateVideoInput>, IVideoAppService
    {
        public VideoAppService(IRepository<Video, long> repository)
           : base(repository)
        {
        }

        public override async Task<PagedResultDto<VideoDto>> GetAll(GetVideoInput input)
        {
            var List = (await Repository.GetAllListAsync()).Where(o => o.CreatorUserId == AbpSession.UserId);
            var count = List.Count();
            var returnList = ObjectMapper.Map<List<VideoDto>>(List).AsQueryable().PageBy(input);
            return new PagedResultDto<VideoDto>(count, returnList.ToList());
        }
    }
}
